/**
 *
 *   @author  Yang Tongfeng   
 * 
 */
String.prototype.replaceAll = function(s1,s2){ 
	return this.replace(new RegExp(s1,"gm"),s2); 
}



var g_yang_saver= {};

function yang_loop(param){
	$(".yang_loop").each(function(index,item){
		var loop_outer = $(this);
		var looper_id = $(this).attr("id");
		var href=$(this).attr("data-source");
		var empty = $(this).attr("empty");
		
	    var html = null;
		if(typeof looper_id != "undefined" ){
			html =g_yang_saver[looper_id];
		}
		if("undefined" == typeof html || html == null){
			html = loop_outer.html();
			g_yang_saver[looper_id] = loop_outer.html();
		}
	    loop_outer.html("");
		//alert(href);	
		if(typeof(param) != "undefined"){
			href = href+"?"+param;
		}
		$.get(href,function(data,status){
			console.log("data type = "+typeof(data));
			if(typeof(data) == 'string'){
				console.log("error data"+data);
				return;
			}
			if(data.length == 0){
				if("undefined" !=  typeof empty ){
					var empty_e = $(empty);
					empty_e.show();
				}
				return;
			}
			
	    	
	    	for(var i = 0;i< data.length;i++){
	    		console.log("process "+i+"");
	    		var myhtml = html+"";
	    		var item = data[i];
	    		for(var key in item){
	    			myhtml = myhtml.replaceAll("{"+key+"}",item[key]);
	    		}
	    		loop_outer.append(myhtml);
	    	} 
		});
	});

}


String.prototype.getAfter=function(mark){
	var pos = this.indexOf(mark);
	if(pos < 0 )return null;
	return this.substr(pos+mark.length);
}